package com.dosh;

import android.app.Activity;
import android.database.Cursor;
/**
 * The Job class describes an entry in the Budget table.
 * A Budget is needed to book jobs. 
 * The fields budget_ID, name, amount and user_ID are necessary for a table entry.
 */
public class Budget extends Activity{
	/**
	 * The ID of the Budget entry
	 */
	public long budget_ID;
	/**
	 * The name of the Budget
	 */
	public String name;
	/**
	 * The Budgets amount
	 */
	public int amount;
	/**
	 * A short description of the Budget
	 */
	public String description;
	/**
	 * The Budget belongs to this User
	 */
	public long user_ID;
	/**
	 * A short reason for this Budget
	 */
	public String reason;
	/**
	 * The actual amount of the Budget
	 */
	public long actual_amount;
	
	/**
	 * This Constructor is used, if there is no entry in the database.
	 * @param dba A reference to the DBAdapter
	 */
	public Budget(String name, int amount, String description, String reason, long user_id, DBAdapter dba) {

		this.name = name;
		this.amount = amount;
		this.description = description;
		this.user_ID = user_id;
		this.reason = reason;
		this.actual_amount = amount;
		
		dba.open();
		this.budget_ID = dba.insertBudget(name, amount, description, reason, user_id, amount);
		dba.close();
	}
	/**
	 * This Constructor is used, if there an entry already exists in the database.
	 * @param dba A reference to the DBAdapter
	 */
	public Budget(long budget_ID, DBAdapter dba) {

		this.budget_ID = budget_ID;
		dba.open();
		Cursor bCursor = dba.SELECTbyId("Budget", budget_ID);
		dba.close();
		this.name = bCursor.getString(1);
		this.amount = bCursor.getInt(2);
		this.description = bCursor.getString(3);
		//this.actual_amount = bCursor.getInt(6);
		
	}	
	/**
	 * This method updates the table entry
	 * @param dba A reference to the DBAdapter
	 * @return gives information,if the update was successful
	 */
	public boolean update(DBAdapter dba) 
	{
		boolean bool = true;
		
		dba.open();
		bool = dba.update("Budget", this.budget_ID, "Amount", this.amount);
		bool = dba.update("Budget", this.budget_ID, "User_ID", this.user_ID);
		bool = dba.update("Budget", this.budget_ID, "Name", this.name);
		bool = dba.update("Budget", this.budget_ID, "Description", this.description);
		bool = dba.update("Budget", this.budget_ID, "Reason", this.reason);
		dba.close();
		
		return bool;
	}
}
